rest_prepare_{$this->post_type}
Filter HookDescription
Filters the post data for a REST API response. The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. Possible hook names include: - `rest_prepare_post` - `rest_prepare_page` - `rest_prepare_attachment`Hook Information
File Location |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
View on GitHub
|
Hook Type | Filter |
Line Number | 2136 |
Hook Parameters
Type | Name | Description |
---|---|---|
WP_REST_Response
|
$response
|
The response object. |
WP_Post
|
$post
|
Post object. |
WP_REST_Request
|
$request
|
Request object. |
Usage Examples
Basic Usage
<?php
// Hook into rest_prepare_{$this->post_type}
add_filter('rest_prepare_{$this->post_type}', 'my_custom_filter', 10, 3);
function my_custom_filter($response, $post, $request) {
// Your custom filtering logic here
return $response;
}
Source Code Context
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:2136
- How this hook is used in WordPress core
<?php
2131 *
2132 * @param WP_REST_Response $response The response object.
2133 * @param WP_Post $post Post object.
2134 * @param WP_REST_Request $request Request object.
2135 */
2136 return apply_filters( "rest_prepare_{$this->post_type}", $response, $post, $request );
2137 }
2138
2139 /**
2140 * Overwrites the default protected and private title format.
2141 *
PHP Documentation
<?php
/**
* Filters the post data for a REST API response.
*
* The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
*
* Possible hook names include:
*
* - `rest_prepare_post`
* - `rest_prepare_page`
* - `rest_prepare_attachment`
*
* @since 4.7.0
*
* @param WP_REST_Response $response The response object.
* @param WP_Post $post Post object.
* @param WP_REST_Request $request Request object.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
Related Hooks
Related hooks will be displayed here in future updates.